package com.xieyong.leetcode;

public class Leetcode3270 {

    public static void main(String[] args) {
        Leetcode3270 leetcode = new Leetcode3270();
        int num1 = 1, num2 = 10, num3 = 100;
        int i = leetcode.generateKey(num1, num2, num3);
        System.out.println(i);
    }


    public int generateKey(int num1, int num2, int num3) {
        StringBuffer sb = new StringBuffer();
        for (int i = 3; i >= 0; i--) {
            int n1 = (int)(num1 % Math.pow(10,i + 1) / Math.pow(10,i));
            int n2 = (int)(num2 % Math.pow(10,i + 1) / Math.pow(10,i));
            int n3 = (int)(num3 % Math.pow(10,i + 1) / Math.pow(10,i));
            int min = Math.min(n1,Math.min(n2,n3));
            sb.append(min);
        }
        return Integer.parseInt(sb.toString());
    }
//       题解中的这个方法也很好，思路更加清晰
//    public int generateKey(int num1, int num2, int num3) {
//        int key = 0;
//        for (int p = 1; num1 > 0 && num2 > 0 && num3 > 0; p *= 10) {
//            key += Math.min(Math.min(num1 % 10, num2 % 10), num3 % 10) * p;
//            num1 /= 10;
//            num2 /= 10;
//            num3 /= 10;
//        }
//        return key;
//    }
}
